package logic

import (
	"context"
	"github.com/eeppee_admin/clouddisk/service/internal/svc"
	"github.com/eeppee_admin/clouddisk/service/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShareBasicDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShareBasicDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShareBasicDetailLogic {
	return &ShareBasicDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}


// http GET :8888/share/basic/detail identity=dcf31a17-a7b8-4cf5-bcd2-ecad9996499d
func (l *ShareBasicDetailLogic) ShareBasicDetail(req *types.ShareBasicDetailRequest) (resp *types.ShareBasicDetailResponse, err error) {
	// 对分享记录的点击次数 + 1
	_, err = l.svcCtx.Engine.Exec("update "+ "sharetable" +" set click_num = click_num + 1 where identity = ?", req.Identity)
	if err != nil {
		return
	}

	resp = new(types.ShareBasicDetailResponse)
	// 获取资源的详细信息
	_, err = l.svcCtx.Engine.Table("sharetable").
		Select("sharetable.store_identity, userstore.name, storepool.ext, storepool.size, storepool.path").
		Join("LEFT", "storepool", "sharetable.store_identity = storepool.identity").
		Join("LEFT", "userstore", "userstore.identity = sharetable.store_identity").
		// Save into Response
		Where("sharetable.identity = ?", req.Identity).Get(resp)

	return
}
